package com.clementheliou.cheliou.web.util.date;

import java.util.Date;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.clementheliou.cheliou.web.util.number.NumberUtils;

/**
 * Utilities about the {@link Date} class.
 * 
 * @author Clément HELIOU (clement.heliou@gmail.com)
 * @see {@link Component};
 * @see {@link Date}.
 * @since 1.0
 */
@Component
public class DateUtils {

	/**
	 * The number of seconds in a year. This values is equals to the following
	 * calculation: <code>60s x 60m x 24h x 365d</code>.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	public static final int SECONDS_PER_YEAR = 31536000;

	/**
	 * Utilities about numbers.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @see {@link Autowired};
	 * @see {@link NumberUtils}.
	 * @since 1.0
	 */
	@Autowired
	private NumberUtils numberUtil;

	/**
	 * Gets the sum of the current date numbers. That is to say
	 * <tt>d+d+m+m+y+y+y+y</tt>.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @return the sum of the current date numbers.
	 * @since 1.0
	 */
	public int getSumOfCurrentDateNumbers() {
		final DateTime now = new DateTime();
		final int day = now.getDayOfMonth(), month = now.getMonthOfYear(), year = now.getYear();
		return numberUtil.getSumOfIntegerDigits(day) + numberUtil.getSumOfIntegerDigits(month) + numberUtil.getSumOfIntegerDigits(year);
	}
}
